package cn.rkylin.oms.aftersale.sysreturn.dao.impl;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.aftersale.sysreturn.dao.ISysReturnSkuDAO;
import cn.rkylin.oms.aftersale.sysreturn.domain.SysReturnSku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 类名:SysReturnSkuDAOImpl <br/>
 * 作用: 退货单明细数据访问类. <br/>
 * 创建原因:	 退货单明细数据库操作. <br/>
 * 创建时间:     2017年9月28日 下午8:17:57 <br/>
 *
 * @author zhanghao
 * @version v1.0
 */
@Repository("sysReturnSkuDAO")
public class SysReturnSkuDAOImpl implements ISysReturnSkuDAO {
    @Autowired
    IDataBaseFactory dao;

    String STATEMENT_INSERT_NOT_EXISTS = "insertNotExistsSysReturnSku";
    String STATEMENT_INSERT_SELECTIVE = "insertSelectiveSysReturnSku";
    String STATEMENT_UPDATE_SELECTIVE = "updateByPrimaryKeySelectiveSysReturnSku";
    String STATEMENT_UPDATE_SELECTIVE_BY_AUTO_SYSRETURN = "updateSelectivebyAutoSysReturn";
    String STATEMENT_SELECT_BYRETURNID = "selectByReturnIdSysReturnSku";
    String STATEMENT_SELECT_BYRETURNSKUID = "selectByReturnSkuIdSysReturnSku";

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#deleteByPrimaryKey(java.lang.String)
     */
    @Override
    public int deleteByPrimaryKey(String refundSkuId) {

        return 0;
    }

    /**
     * 插入退货单明细.
     *
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#insert(cn.rkylin.oms.sysreturn.domain.SysReturnSku)
     */
    @Override
    public int insert(SysReturnSku record) throws Exception {
        return dao.insert(STATEMENT_INSERT_SELECTIVE, record);
    }

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#insertSelective(cn.rkylin.oms.sysreturn.domain.SysReturnSku)
     */
    @Override
    public int insertSelective(SysReturnSku record) {

        return 0;
    }

    /**
     * @throws Exception 
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#selectByPrimaryKey(java.lang.String)
     */
    @Override
    public SysReturnSku selectByPrimaryKey(String returnSkuId) throws Exception {

        return dao.findOne("selectByPrimaryKeySysReturnSku", returnSkuId);
    }

    /**
     * 更新系统退货单商品明细
     *
     * @param record
     * @return
     * @throws Exception
     */
    @Override
    public int updateByPrimaryKeySelective(SysReturnSku record) throws Exception {
        return dao.update(STATEMENT_UPDATE_SELECTIVE, record);
    }

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#updateByPrimaryKey(cn.rkylin.oms.sysreturn.domain.SysReturnSku)
     */
    @Override
    public int updateByPrimaryKey(SysReturnSku record) {

        return 0;
    }

    /**
     * 插入不存在的退货单明细.
     *
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#insertNotExistSku(cn.rkylin.oms.sysreturn.domain.SysReturnSku)
     */
    @Override
    public int insertNotExistSku(SysReturnSku sysReturnSku) throws Exception {
        return dao.insert(STATEMENT_INSERT_NOT_EXISTS, sysReturnSku);
    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnSkuDAO#deleteByAutoSysReturnID(java.lang.String)
     */
    @Override
    public int deleteByAutoSysReturnID(String returnId) throws Exception {
        SysReturnSku param = new SysReturnSku();
        param.setDeleted("y");
        param.setReturnId(returnId);
        return dao.update(STATEMENT_UPDATE_SELECTIVE_BY_AUTO_SYSRETURN, param);
    }

    /**
     * 获取系统退货单商品明细
     *
     * @param returnId
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnSku> selectByReturnId(String returnId) throws Exception {
        return dao.findList(STATEMENT_SELECT_BYRETURNID, returnId);
    }

    @Override
    public List<SysReturnSku> selectByReturnSkuIdSysReturnSku(String returnSkuId) throws Exception {
        return dao.findList("selectByReturnSkuIdSysReturnSku", returnSkuId);
    }

    /**
     * 判断退货单的来源单据的发货单是否已发货
     *
     * @param returnId
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnSku> apprCheckCountByReturnId(String returnId) throws Exception {
        return dao.findList("selectSysReturnForShiporderCount", returnId);
    }

    /**
     * 判断退货单的来源单据的发货单是否商品已经发货
     *
     * @param returnId
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnSku> apprCheckShiporderSkuByReturnId(String returnId) throws Exception {
        return dao.findList("selectSysReturnForShiporderSku", returnId);
    }

    /**
     * 判断商品是否关联过 菜鸟商品
     *
     * @param sysReturnSku
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnSku> selectSysReturnSkuForCainiao(SysReturnSku sysReturnSku) throws Exception {
        return dao.findAllList("selectSysReturnSkuForCainiao", sysReturnSku);
    }

}

